package com.tuozixuan.onesql.service;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.google.common.base.Functions;
import com.tuozixuan.onesql.db.Column;
import com.tuozixuan.onesql.mysql.BaseDao;

public class TableContext {
    
    private String databaseName;
    
    private String tableName;
    
    private List<Column> columnList;
    
    private Map<String, Column> columnMap;

    public TableContext(String databaseName, String tableName) {
        
        this.databaseName = databaseName;
        this.tableName = tableName;
        try {
            columnList = new BaseDao().getColumnList(tableName);
            columnMap = columnList.stream().collect(Collectors.toMap(Column::getName, Functions.identity()));
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getDatabaseName() {
        return databaseName;
    }

    public void setDatabaseName(String databaseName) {
        this.databaseName = databaseName;
    }

    public List<Column> getColumnList() {
        return columnList;
    }

    public void setColumnList(List<Column> columnList) {
        this.columnList = columnList;
    }
    
    public Map<String, Column> getColumnMap() {
        return columnMap;
    }

    public void setColumnMap(Map<String, Column> columnMap) {
        this.columnMap = columnMap;
    }
}
